//   "M+" : parseInt(((this.getMonth()+1)+"").replace("0","")),                 //月份 
//   "d+" : parseInt(((this.getDate()+"").replace("0",""))),                     //日
Date.prototype.format = function(fmt) { 
     var o = { 
        "M+" : this.getMonth()+1,                 //月份 
        "d+" : this.getDate(),                    //日 
        "h+" : this.getHours(),                   //小时 
        "m+" : this.getMinutes(),                 //分 
        "s+" : this.getSeconds(),                 //秒 
        "q+" : Math.floor((this.getMonth()+3)/3), //季度 
        "S"  : this.getMilliseconds()             //毫秒 
    }; 
    if(/(y+)/.test(fmt)) {
            fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
    }
     for(var k in o) {
        if(new RegExp("("+ k +")").test(fmt)){
            if (k=="M+" || k=="d+"){
             fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("0"+ o[k]).substr((""+ o[k]).length)));
            }else{
             fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));   
            }
         }
     }

    return fmt; 
}        



cc.Class({
    extends: cc.Component,

    properties: {
        className:"finalGameOver",
        content:{
            default:null,
            type:cc.Node,
        }
    },

    // LIFE-CYCLE CALLBACKS:
    onLoad () {
        console.log("初始化");
        this.node.thisJS = this;
        this.initUI();
    },

    start: function () {
       
    },

    initUI: function(){          
        this.roomid =  cc.find("roomid",this.node);
        this.time =  cc.find("time",this.node);
        this.jushu =  cc.find("jushu",this.node);
        this.creator =  cc.find("creator",this.node);
        this.itemModel = cc.find("gameoveritem",this.node);   
    },
    // 最终结算 1666
    /*
        message FinalGameOver{
            optional int32 desk_id = 1;     //桌子ID 
            optional int32 stop_time = 2;   //结束时间
            optional string bank_name = 3;  //房主昵称
            optional int32 play_count = 4;  //总的局数
            
            message user_info       //结算玩家信息
            {
                optional int32 uin = 1;         //用户ID
                optional string nick = 2;       //用户昵称
                optional int32 score = 3;       //用户分数
                optional int32 flag = 4;        //用户标识  1.大赢家 
            }
            repeated user_info users = 5;
        }
    */

  
    updateView:function(info){
        var time1 = new Date().format("yyyy-MM-dd hh:mm");
        this.roomid.getComponent(cc.Label).string  = "房间号:" + info.desk_id ;
        this.time.getComponent(cc.Label).string  = "" + time1 ;
        this.jushu.getComponent(cc.Label).string  = (info.play_count || 10)+"局" ;
        this.creator.getComponent(cc.Label).string  = "房主:"+info.bank_name;
        console.log("添加子节点 info");
        dump(info.user_info);
        for(var k in info.users){
            var tempInfo = info.users[k] ;
            var cItem  = cc.instantiate(this.itemModel);
            cItem.setPosition(cc.p(0,0));
            var dayingjia = cc.find("dayingjia",cItem);
            var name = cc.find("name",cItem);
            var score = cc.find("score",cItem);
            name.getComponent(cc.Label).string = tempInfo.nick ;
            
            if(tempInfo.flag == 1){
                dayingjia.active = true ;
            }else{
                dayingjia.active = false ;
            }
            if(tempInfo.score>=0){
                score.color = new cc.Color(228, 228, 35);
                name.color = new cc.Color(220, 228, 35);
                score.getComponent(cc.Label).string = "+" + tempInfo.score ;
            }else{
                score.color= new cc.Color(255, 255, 255);
                name.color = new cc.Color(255, 255, 255);
                score.getComponent(cc.Label).string = "" + tempInfo.score ;
            }
            console.log("添加子节点");
            this.content.addChild(cItem);
        }
    },
    shot: function () {

        // 注意，EditBox，VideoPlayer，Webview 等控件无法被包含在截图里面
        // 因为这是 OpenGL 的渲染到纹理的功能，上面提到的控件不是由引擎绘制的
        console.log("开始截屏");
        if (CC_JSB) {

            // 创建 renderTexture
            var renderTexture = cc.RenderTexture.create(720,1280);
            
            //实际截屏的代码
            renderTexture.begin();
            //this.richText.node 是我们要截图的节点，如果要截整个屏幕，可以把 this.richText 换成 Canvas 切点即可
            this.node._sgNode.visit();
            renderTexture.end();

            renderTexture.saveToFile("demo.png",cc.ImageFormat.PNG, true, function () {
                cc.log("capture screen successfully!");
            });
            //打印截图路径
            cc.log(jsb.fileUtils.getWritablePath());
        }

    },

});